package com.objecteffects.template.web.action;

import java.util.HashMap;
import java.util.Map;

/**
 * Wants to be in the template.web.action package since it references
 * the ActionBeans.
 *
 * Effective Java, Josh Bloch, Item 30.
 *
 * @author Rusty Wright
 */
public enum TumblrMethod {
    // AVATAR(AvatarActionBean.class), /* receives binary */
    BLOG_INFO(BlogInfoActionBean.class),
    USER_INFO(UserInfoActionBean.class),
    FOLLOWERS(FollowersActionBean.class),
    LIKES(LikesActionBean.class),
    POSTS(PostsActionBean.class),
    EDIT(null),
    QUEUE(QueueActionBean.class),
    DRAFTS(DraftsActionBean.class),
    SUBMISSION(null);

    private final String lcName;
    private final Class<? extends BaseActionBean> actionBean;

    private static final Map<String, TumblrMethod> STRING_TO_ENUM =
        new HashMap<>();

    TumblrMethod(final Class<? extends BaseActionBean> _actionBean) {
        this.lcName = this.name().toLowerCase();

        this.actionBean = _actionBean;
    }

    static {
        for (final TumblrMethod tm : values()) {
            TumblrMethod.STRING_TO_ENUM.put(tm.toString(), tm);
        }
    }

    /*
     * Returns TumblrMethod for string, or null if string is invalid.
     */
    public static TumblrMethod fromString(final String name) {
        return TumblrMethod.STRING_TO_ENUM.get(name);
    }

    public Class<? extends BaseActionBean> toActionBean() {
        return this.actionBean;
    }

    @Override
    public String toString() {
        return this.lcName;
    }
}
